var Stats = function () {
  var s = Date.now(),
    q = s;
  var k = 0,
    o = Infinity,
    n = 0;
  var c = 0,
    g = Infinity,
    f = 0;
  var i = 0,
    j = 0;
  var b = document.createElement('div');
  b.id = 'stats';
  b.addEventListener(
    'mousedown',
    function (u) {
      u.preventDefault();
      r(++j % 2);
    },
    false
  );
  b.style.cssText = 'width:80px;opacity:0.9;cursor:pointer';
  var d = document.createElement('div');
  d.id = 'fps';
  d.style.cssText = 'padding:0 0 3px 3px;text-align:left;background-color:#002';
  b.appendChild(d);
  var h = document.createElement('div');
  h.id = 'fpsText';
  h.style.cssText =
    'color:#0ff;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';
  h.innerHTML = 'FPS';
  d.appendChild(h);
  var e = document.createElement('div');
  e.id = 'fpsGraph';
  e.style.cssText =
    'position:relative;width:74px;height:30px;background-color:#0ff';
  d.appendChild(e);
  while (e.children.length < 74) {
    var a = document.createElement('span');
    a.style.cssText = 'width:1px;height:30px;float:left;background-color:#113';
    e.appendChild(a);
  }
  var l = document.createElement('div');
  l.id = 'ms';
  l.style.cssText =
    'padding:0 0 3px 3px;text-align:left;background-color:#020;display:none';
  b.appendChild(l);
  var p = document.createElement('div');
  p.id = 'msText';
  p.style.cssText =
    'color:#0f0;font-family:Helvetica,Arial,sans-serif;font-size:9px;font-weight:bold;line-height:15px';
  p.innerHTML = 'MS';
  l.appendChild(p);
  var m = document.createElement('div');
  m.id = 'msGraph';
  m.style.cssText =
    'position:relative;width:74px;height:30px;background-color:#0f0';
  l.appendChild(m);
  while (m.children.length < 74) {
    var a = document.createElement('span');
    a.style.cssText = 'width:1px;height:30px;float:left;background-color:#131';
    m.appendChild(a);
  }
  var r = function (u) {
    j = u;
    switch (j) {
      case 0:
        d.style.display = 'block';
        l.style.display = 'none';
        break;
      case 1:
        d.style.display = 'none';
        l.style.display = 'block';
        break;
    }
  };
  var t = function (v, w) {
    var u = v.appendChild(v.firstChild);
    u.style.height = w + 'px';
  };
  return {
    REVISION: 11,
    domElement: b,
    setMode: r,
    begin: function () {
      s = Date.now();
    },
    end: function () {
      var u = Date.now();
      k = u - s;
      o = Math.min(o, k);
      n = Math.max(n, k);
      p.textContent = k + ' MS (' + o + '-' + n + ')';
      t(m, Math.min(30, 30 - (k / 200) * 30));
      i++;
      if (u > q + 1000) {
        c = Math.round((i * 1000) / (u - q));
        g = Math.min(g, c);
        f = Math.max(f, c);
        h.textContent = c + ' FPS (' + g + '-' + f + ')';
        t(e, Math.min(30, 30 - (c / 100) * 30));
        q = u;
        i = 0;
      }
      return u;
    },
    update: function () {
      s = this.end();
    },
  };
};
